/**
 *
 */
package com.tongzhan.utils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 读取config.properties的工具类
 *
 * @author mintonzhang
 * 2018年8月15日
 */
public class ConfigPropertiesUtil {

    /**
     * 读取配置文件
     */
    public static Properties properties = new Properties();

    static {
        try {
            String path = "config.properties";
            InputStream inStream = ConfigPropertiesUtil.class.getClassLoader().getResourceAsStream(path);
            if (inStream == null) {
                inStream = ConfigPropertiesUtil.class.getClassLoader().getResourceAsStream("/" + path);
            }
            properties.load(inStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 检查路径是否存在，不存在则创建路径
     *
     * @param path
     */
    public static void checkPath(String path) {
        String[] paths = null;
        if (path.contains("/")) {
            paths = path.split(File.separator + File.separator);
            System.out.println(paths);
        } else {
            paths = path.split(File.separator + File.separator);
        }
        if (paths == null || paths.length == 0) {
            return;
        }
        String pathdir = "";
        for (String string : paths) {
            pathdir = pathdir + string + File.separator;
            File file = new File(pathdir);
            if (!file.exists()) {
                file.mkdir();
            }
        }
    }

    // 上传文件的目录
    public static String getUploadFilePath() {
        return properties.getProperty("uploadFilePath");
    }

    // 文件访问路径
    public static String getFileRootUrl() {
        return properties.getProperty("fileRootUrl");
    }

    // 工程访问路径
    public static String getWebRootUrl() {
        return properties.getProperty("webRootUrl");
    }

    // 苹果推送证书目录
    public static String getIosPushPath() {
        return properties.getProperty("ios_push_file_path");
    }

    // 苹果推送证书密码
    public static String getIosAuntPushPath() {
        return properties.getProperty("ios_aunt_push_file_path");
    }

    // 苹果推送证书密码
    public static String getIosPushPsw() {
        return properties.getProperty("ios_push_file_psw");
    }
    
    // 获取用户信息的接口
    public static String getUserInfoInterface() {
    	return properties.getProperty("requestinterfaceaddress");
    }

}
